<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
<div id="app">
    <span v-if="loginFlag == 'username'">
        <label for="username">用户名：</label>
        <input type="text" id="username" :placeholder="message" :key="key">
    </span>
    <span v-else>
        <label for="email">邮箱：</label>
        <input type="text" id="email" :placeholder="message" :key="key">
    </span>
    <br>
    <button v-on:click="changeLoginType()">切换类型</button>
</div>

<script src="../js/vue.js"></script>
<script>
    const app = new Vue({
        el: '#app',
        data: {
            loginFlag: 'username',
            message: '请输入用户名',
            key: 'key for username'
        },
        methods: {
            changeLoginType(){
                if (this.loginFlag == 'username') {
                    this.loginFlag = 'email'
                    this.message = '请输入邮箱'
                    this.key = 'key for email'
                } else {
                    this.loginFlag = 'username'
                    this.message = '请输入用户名'
                    this.key = 'key for username'
                }
            }
        },
    })
</script>
</body>
</html>